package com.app.studyroom.adapter;

import com.app.studyroom.R;
import com.app.studyroom.api.model.ssrSeat.SsrSeatBooking;
import com.app.studyroom.mapper.ApprovalStatusMapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;



import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class BookingDetailAdapter extends RecyclerView.Adapter<BookingDetailAdapter.DetailHolder> {



    private final List<SsrSeatBooking> bookingList;

    public BookingDetailAdapter(List<SsrSeatBooking> list) {
        this.bookingList = list;
    }

    @NonNull
    @Override
    public DetailHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_booking_detail, parent, false);
        return new DetailHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull DetailHolder holder, int position) {
        SsrSeatBooking item = bookingList.get(position);
        holder.tvTime.setText(item.getBookingStartTime().substring(5, 16) + " ~ " + item.getBookingEndTime().substring(5, 16));
        holder.tvStatus.setText(ApprovalStatusMapper.getNameByCode(item.getApprovalStatus()));
    }


    @Override
    public int getItemCount() {
        return bookingList.size();
    }

    static class DetailHolder extends RecyclerView.ViewHolder {
        TextView tvTime, tvStatus;

        public DetailHolder(@NonNull View itemView) {
            super(itemView);
            tvTime = itemView.findViewById(R.id.tv_booking_time);
            tvStatus = itemView.findViewById(R.id.tv_approval_status);
        }
    }
}
